home *** CD-ROM | disk | FTP | other *** search
-
- ----------------------------------------------------------------------
-
- **** *** **** **** *** ***
- ******** *** ****** ******** *** ***
- *** ** *** *** *** *** ** *** ***
- **** *** ******** **** ********
- **** *** ******** **** ********
- ** *** *** *** *** ** *** *** ***
- ******** ******* *** *** ******** *** ***
- **** ******* *** *** **** *** ***
-
- A utility to compress BASIC programs
-
- ----------------------------------------------------------------------
-
- Now that we have lots of memory for BASIC programs (don't we?), there
- is no excuse, as there once was, for being mean with REMs, blank lines
- and the length of variable names. These can make all the difference
- between a program that is easy to follow and to modify and one that is
- totally impenetrable. Yet even magazines such as this sometimes nod;
- though the editorial space saved by an unadorned listing can be more
- than offset by a long textual explanation.
-
- Yet there is still value in compressing BASIC programs which may be
- considerable if you wish to store utilities in EPROM or battery-backed
- RAM on a ROM podule. This program, for example, can be reduced in
- length by more than 50%; 25-30% is however more typical.
-
- Besides, a compressed program runs appreciably faster. A run of the
- full version of SLASH on an example 30k program including assembler
- took 54 seconds compared with 41 seconds using the fully compressed
- version. And a compressed version of the variant of SLASH (SLASHINTG
- on the disc) which uses the resident integers in place of normal
- integers runs even faster; 35 seconds for the example. Of course, it
- is almost impossible to read the code but this may be a useful ploy
- sometimes to 'protect' your ideas!
-
- This program, SLASH, allows you to remove any or all of: redundant
- leading spaces and colons, REMs, and empty lines, in that order. Using
- the BASIC Editor to do this is extremely tedious and in any case it
- can be hazardous because it is only too easy accidentally to
- concatenate lines which damage the logic flow or even to delete a line
- completely. Thus comprehensive testing AFTER compression is essential:
- a great disincentive to doing it!
-
- Some compression programs go further than this one; eg, they remove
- spaces within lines and concatenate them. This does save further
- space, though not all that much, but the line analysis needs to be
- very much more complex than in this program to avoid illegal
- concatenation (such as in extended IF...THEN...ELSE and CASE...OF) and
- to preserve spaces in explicit strings. Thus such programs tend to be
- very slow unless they are in machine code.
-
- In SLASH you also have the option to enter a range of line numbers
- which will NOT be processed, whatever the other options set. This is
- useful if you want to preserve a heading, a group of explanatory lines
- or a fully commented procedure. You will see these lines flagged
- '[Skip]' during processing. The compressed program has a line added:
- '0REM>new-path/file-name' so the system can refer to it properly (this
- is not done if you select no changes!). If the old program already had
- a line 0 you may find another in the new program, but you can easily
- re-number it. The % compression and time taken are reported at the
- end.
-
- SLASH deals with assembler remarks (introduced by ';' or '\' as well
- as 'REM') but unfortunately this needs detection of entry to and exit
- from the assembler which is made difficult by the use of '[' and ']'
- within the assembler syntax and slows processing. Assembler lines are
- flagged whilst they are being processed. The algorithm will NOT deal
- correctly with remarks EMBEDDED in the assembler; it assumes that they
- are always at the ends of lines, or on separate ones, like REMs.
-
- The program will not allow you to attempt to compress a directory or a
- file whose 'type' is not BASIC, or to save to an existing locked file.
- It will warn you of overwriting the original or any existing UNLOCKED
- file, or if there is no disc in the nominated drive. In each case you
- can go back and correct the input. The compressed file can be put
- straight into the RFS by entering 'RFS:$.Library.<filename>' for the
- output file. ESCAPE ends the program at any point without damaging
- files.
-
- The program itself is 'linear' apart from the central double loop, so
- subroutines and procedures have not been used, just 3 functions. It
- uses flags extensively to control execution flow depending on the
- options chosen.
-
- The new file is overlayed on top of the original in the byte array
- 'filespace', line by line. The original file is loaded into
- 'filespace' offset sufficiently for the title line (up to one screen
- line long) to be inserted into the new file. There are two file
- pointers into 'filespace' keeping note of the beginning of the
- unprocessed old file and of the end of the accumulating new one. There
- are also two line pointers; one into the section of 'filespace'
- holding the current old line, and the other into 'linespace' in which
- the replacement line is being constructed. Note that BASIC lines
- actually BEGIN with &D, but here the &D's are used as line
- TERMINATORS.
-
- One other programming feature of interest is the use of 'SYS
- "OS_File",n' calls to allow economical but comprehensive error
- trapping in the file nomination routines. Note how object type, file
- type and access status are extracted (lines 570-600 and 670-720), and
- how file type is set during saving (line 2100). The SYS "OS_file"
- calls mostly require a POINTER in Register 1 to a path or filename
- anywhere in memory. In BASIC a string variable name IS simply a
- pointer, so the 'name$' is all that need be given to the SYS call, as
- exemplified here.
-
-
-
- ----------------------------------------------------------------------
-
- Brian Carroll December 1988
-
- ----------------------------------------------------------------------
-